package com.imcode;

import java.io.*;

public class BufferedStreamDemo {

    public static void main(String[] args) throws IOException {
        long t1 = System.currentTimeMillis();
        //1.按字节读取要复制的文件1.txt
        // 创建字节缓冲输入流
        InputStream in = new BufferedInputStream(new FileInputStream("file/1.txt"));
        // 创建字节缓冲输出流
        OutputStream out = new BufferedOutputStream(new FileOutputStream("file/6.txt"));
        //2.读取1.txt的内容
        byte[] bytes = new byte[1024];
        int len = 0;// 存储每次读取到的字节数
        while ((len = in.read(bytes)) != -1) {
            out.write(bytes,0,len);
        }
        //3.关闭流
        in.close();
        out.close();
        long t2 = System.currentTimeMillis();

        long time = (t2 - t1)/1000;
        System.out.println("基本字节流复制文件:" + time + "s");
    }
}
//基本字节流复制文件:3s